package com.GB26875_3_2011.enable;

import com.GB26875_3_2011.codec.MessageEncoder;
import com.GB26875_3_2011.config.GB26875Properties;
import com.GB26875_3_2011.message.MessageSimpleHandler;
import com.GB26875_3_2011.server.TCPServer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.EventExecutorGroup;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.PostConstruct;

/**
 * @author 蒋仕国
 * @projectName GB26875_3_211
 * @ClassName AutoServer
 * @date 2025-01-13 13:29
 * @Description: TODO []
 */
@AllArgsConstructor
@Slf4j
public class AutoServer {

    private final GB26875Properties gB26875Properties;
    private final MessageEncoder messageEncoder;
    private final EventLoopGroup bossGroup;
    private final EventLoopGroup workerGroup;
    private final EventExecutorGroup businessGroup;
    private final MessageSimpleHandler messageSimpleHandler;

    @PostConstruct
    public void init() throws Exception {

        if (gB26875Properties.getServerType() == GB26875Properties.ServerType.TCP) {
            new TCPServer(gB26875Properties,
                    messageEncoder,
                    bossGroup,
                    workerGroup,
                    businessGroup,
                    messageSimpleHandler).start();
        } else {
            log.info("当前GB26875仅支持TCP");
        }
    }
}
